<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      html,
      body {
        width: 100%;
      }
      .ball {
        width: 200px;
        height: 200px;
        border-radius: 50%;
        background: palegreen;
        margin: 60px auto;
        transition: all 2s;
      }
      .app {
        width: 100%;
        height: auto;
        display: flex;
        justify-content: center;
      }
      .app button {
        width: 100px;
        height: 30px;
      }
    </style>
  </head>
  <body>
    <div id="app"></div>
    <script src="./libs/react.js"></script>
    <script src="./libs/react-dom.js"></script>
    <script src="./libs/babel.min.js"></script>
    <script type="text/babel">
      const { Component } = React;

      class Ball extends Component {
        constructor(props) {
          super(props);
        }
        render() {
          return (
            <div className="ball" style={{ background: this.props.color }} />
          );
        }
      }

      class App extends Component {
        constructor(props) {
          super(props);
          this.state = {
            color: "palegreen",
          };
          //   this.changeColor = this.changeColor.bind(this);
        }
        changeColor(color) {
          this.setState({
            color,
          });
        }
        render() {
          //   const { color } = this.state;
          return (
            <div className="app">
              <button onClick={() => this.changeColor("red")}>红色</button>
              <button onClick={() => this.changeColor("orange")}>橙色</button>
              <button onClick={() => this.changeColor("green")}>绿色</button>
              <button onClick={() => this.changeColor("blue")}>蓝色</button>
              <Ball color={this.state.color} />
            </div>
          );
        }
      }
      ReactDOM.render(<App />, document.getElementById("app"));
    </script>
  </body>
</html>
